package top.xia17.plugins.fast.common.model;

import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;

/**
 * 分页数据
 * @author xia17
 * @date 2020/7/22 18:15
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class PageData<T> implements Serializable {

    /**
     * 数据
     */
    @NotNull
    private List<T> data;

    /**
     * 总记录数
     */
    @NotNull
    private Long count;

    /** 附加数据 **/
    private Object extra;


    public PageData<T> setExtra(Object extra){
        this.extra = extra;
        return this;
    }

    public PageData(@NotNull List<T> data, @NotNull Long count) {
        this.data = data;
        this.count = count;
    }

    public static<T> PageData<T> empty(){
        return new PageData<T>(Collections.emptyList(),0L);
    }
}
